From: Bilal Elmoussaoui Date: Wed, 15 Apr 2026 07:31:20 +0000 (+0200) Subject: croco: Prefer using g_clear_* macros X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~10^2^2~53 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=2e3f213248ec787ea8f882cbe9f2bdae68e379cd;p=gnome-shell.git croco: Prefer using g_clear_* macros Part-of: --- diff --git a/src/st/croco/cr-attr-sel.c b/src/st/croco/cr-attr-sel.c index fc8e6ef80..e641e4ecb 100644 --- a/src/st/croco/cr-attr-sel.c +++ b/src/st/croco/cr-attr-sel.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA - * + * * See COPYRIGHTS file for copyrights information. */ @@ -62,11 +62,11 @@ cr_attr_sel_append_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel) { CRAttrSel *cur_sel = NULL; - g_return_val_if_fail (a_this && a_attr_sel, + g_return_val_if_fail (a_this && a_attr_sel, CR_BAD_PARAM_ERROR); - for (cur_sel = a_this; - cur_sel->next; + for (cur_sel = a_this; + cur_sel->next; cur_sel = cur_sel->next) ; cur_sel->next = a_attr_sel; @@ -85,10 +85,10 @@ cr_attr_sel_append_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel) *Returns CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_attr_sel_prepend_attr_sel (CRAttrSel * a_this, +cr_attr_sel_prepend_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel) { - g_return_val_if_fail (a_this && a_attr_sel, + g_return_val_if_fail (a_this && a_attr_sel, CR_BAD_PARAM_ERROR); a_attr_sel->next = a_this; @@ -123,7 +123,7 @@ cr_attr_sel_to_string (CRAttrSel const * a_this) if (cur->name) { guchar *name = NULL; - name = (guchar *) g_strndup (cur->name->stryng->str, + name = (guchar *) g_strndup (cur->name->stryng->str, cur->name->stryng->len); if (name) { g_string_append (str_buf, (const gchar *) name); @@ -135,7 +135,7 @@ cr_attr_sel_to_string (CRAttrSel const * a_this) if (cur->value) { guchar *value = NULL; - value = (guchar *) g_strndup (cur->value->stryng->str, + value = (guchar *) g_strndup (cur->value->stryng->str, cur->value->stryng->len); if (value) { switch (cur->match_way) { @@ -226,9 +226,6 @@ cr_attr_sel_destroy (CRAttrSel * a_this) a_this->next = NULL; } - if (a_this) { - g_free (a_this); - a_this = NULL; - } + g_clear_pointer (&a_this, g_free); } diff --git a/src/st/croco/cr-declaration.c b/src/st/croco/cr-declaration.c index 6c70128a2..1917f62e7 100644 --- a/src/st/croco/cr-declaration.c +++ b/src/st/croco/cr-declaration.c @@ -548,10 +548,7 @@ cr_declaration_to_string (CRDeclaration const * a_this, gulong a_indent) g_string_free (stringue, TRUE); stringue = NULL; } - if (str) { - g_free (str); - str = NULL; - } + g_clear_pointer (&str, g_free); return result; } diff --git a/src/st/croco/cr-doc-handler.c b/src/st/croco/cr-doc-handler.c index b0ef13c07..0806af828 100644 --- a/src/st/croco/cr-doc-handler.c +++ b/src/st/croco/cr-doc-handler.c @@ -251,10 +251,7 @@ cr_doc_handler_destroy (CRDocHandler * a_this) { g_return_if_fail (a_this); - if (a_this->priv) { - g_free (a_this->priv); - a_this->priv = NULL; - } + g_clear_pointer (&a_this->priv, g_free); g_free (a_this); } diff --git a/src/st/croco/cr-fonts.c b/src/st/croco/cr-fonts.c index a64ffc045..da16cf883 100644 --- a/src/st/croco/cr-fonts.c +++ b/src/st/croco/cr-fonts.c @@ -229,10 +229,7 @@ cr_font_family_set_name (CRFontFamily * a_this, guchar * a_name) return CR_BAD_PARAM_ERROR; } - if (a_this->name) { - g_free (a_this->name); - a_this->name = NULL; - } + g_clear_pointer (&a_this->name, g_free); a_this->name = a_name; return CR_OK; @@ -303,10 +300,7 @@ cr_font_family_destroy (CRFontFamily * a_this) for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ; for (; cur_ff; cur_ff = cur_ff->prev) { - if (a_this->name) { - g_free (a_this->name); - a_this->name = NULL; - } + g_clear_pointer (&a_this->name, g_free); if (cur_ff->next) { g_free (cur_ff->next); diff --git a/src/st/croco/cr-input.c b/src/st/croco/cr-input.c index 170d8d971..9a6983bbd 100644 --- a/src/st/croco/cr-input.c +++ b/src/st/croco/cr-input.c @@ -263,10 +263,7 @@ cr_input_new_from_uri (const gchar * a_file_uri, enum CREncoding a_enc) file_ptr = NULL; } - if (buf) { - g_free (buf); - buf = NULL; - } + g_clear_pointer (&buf, g_free); return result; } diff --git a/src/st/croco/cr-om-parser.c b/src/st/croco/cr-om-parser.c index 90f710621..e9fdcd27b 100644 --- a/src/st/croco/cr-om-parser.c +++ b/src/st/croco/cr-om-parser.c @@ -727,10 +727,7 @@ property (CRDocHandler * a_this, return; error: - if (str) { - g_free (str); - str = NULL; - } + g_clear_pointer (&str, g_free); if (decl) { cr_declaration_destroy (decl); @@ -1135,8 +1132,5 @@ cr_om_parser_destroy (CROMParser * a_this) PRIVATE (a_this) = NULL; } - if (a_this) { - g_free (a_this); - a_this = NULL; - } + g_clear_pointer (&a_this, g_free); } diff --git a/src/st/croco/cr-parser.c b/src/st/croco/cr-parser.c index 3f1b36c9a..4abf3b907 100644 --- a/src/st/croco/cr-parser.c +++ b/src/st/croco/cr-parser.c @@ -501,10 +501,7 @@ cr_parser_error_destroy (CRParserError * a_this) { g_return_if_fail (a_this); - if (a_this->msg) { - g_free (a_this->msg); - a_this->msg = NULL; - } + g_clear_pointer (&a_this->msg, g_free); g_free (a_this); } @@ -603,10 +600,7 @@ cr_parser_clear_errors (CRParser * a_this) } } - if (PRIVATE (a_this)->err_stack) { - g_list_free (PRIVATE (a_this)->err_stack); - PRIVATE (a_this)->err_stack = NULL; - } + g_clear_pointer (&PRIVATE (a_this)->err_stack, g_list_free); return CR_OK; } @@ -4524,8 +4518,5 @@ cr_parser_destroy (CRParser * a_this) PRIVATE (a_this) = NULL; } - if (a_this) { - g_free (a_this); - a_this = NULL; /*useless. Just for the sake of coherence */ - } + g_clear_pointer (&a_this, g_free); } diff --git a/src/st/croco/cr-selector.c b/src/st/croco/cr-selector.c index 37f5abc54..179391194 100644 --- a/src/st/croco/cr-selector.c +++ b/src/st/croco/cr-selector.c @@ -273,19 +273,13 @@ cr_selector_destroy (CRSelector * a_this) /*walk backward the list and free each "next element" */ for (cur = cur->prev; cur && cur->prev; cur = cur->prev) { - if (cur->next) { - g_free (cur->next); - cur->next = NULL; - } + g_clear_pointer (&cur->next, g_free); } if (!cur) return; - if (cur->next) { - g_free (cur->next); - cur->next = NULL; - } + g_clear_pointer (&cur->next, g_free); g_free (cur); } diff --git a/src/st/croco/cr-statement.c b/src/st/croco/cr-statement.c index eaeb49f35..778354516 100644 --- a/src/st/croco/cr-statement.c +++ b/src/st/croco/cr-statement.c @@ -625,10 +625,7 @@ cr_statement_ruleset_to_string (CRStatement const * a_this, glong a_indent) g_string_append (stringue, "}"); result = g_string_free (stringue, FALSE); - if (tmp_str) { - g_free (tmp_str); - tmp_str = NULL; - } + g_clear_pointer (&tmp_str, g_free); return result; } @@ -715,10 +712,7 @@ cr_statement_charset_to_string (CRStatement const *a_this, cr_utils_dump_n_chars2 (' ', stringue, a_indent); g_string_append_printf (stringue, "@charset \"%s\" ;", str); - if (str) { - g_free (str); - str = NULL; - } + g_clear_pointer (&str, g_free); } if (stringue) { str = g_string_free (stringue, FALSE); @@ -2764,20 +2758,14 @@ cr_statement_destroy (CRStatement * a_this) /*walk backward and free next element */ for (cur = cur->prev; cur && cur->prev; cur = cur->prev) { - if (cur->next) { - g_free (cur->next); - cur->next = NULL; - } + g_clear_pointer (&cur->next, g_free); } if (!cur) return; /*free the one remaining list */ - if (cur->next) { - g_free (cur->next); - cur->next = NULL; - } + g_clear_pointer (&cur->next, g_free); g_free (cur); cur = NULL; diff --git a/src/st/croco/cr-tknzr.c b/src/st/croco/cr-tknzr.c index 54f18f270..ad800f93b 100644 --- a/src/st/croco/cr-tknzr.c +++ b/src/st/croco/cr-tknzr.c @@ -1610,10 +1610,7 @@ cr_tknzr_new (CRInput * a_input) if (result->priv == NULL) { cr_utils_trace_info ("Out of memory"); - if (result) { - g_free (result); - result = NULL; - } + g_clear_pointer (&result, g_free); return NULL; }